﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;

namespace Infrastructure.Web.Views.Master
{
    public abstract class MasterPresenter
    {
        protected object _View { get; set; }

    }
    public abstract class MasterPresenter<TView> : MasterPresenter
    {
        public TView View { get { return (TView)this._View; } set { this._View = value; } }
        public Page ViewAsPage { get {
            var p = this._View as Page;
            if (p == null) throw new ApplicationException("view is not a page , cast is not valid");
            return p;
        } }
        public UserControl ViewAsUserControl
        {
            get {
                var u = this._View as UserControl;
                if (u == null) throw new ApplicationException("view is not a usercontrol, cast is not valid");
                return u;
            }
        }
        public MasterPage ViewAsMasterPage
        {
            get
            {
                var u = this._View as MasterPage;
                if (u == null) throw new ApplicationException("view is not a masterpage, cast is not valid");
                return u;
            }
        }


        public virtual void OnViewInitialized() { }
        public virtual void OnViewLoaded(){}                


    }
}
